<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <table>
        <tr>
            <td></td>

            <td colspan="4">简易计算器</td>
        </tr>
        <tr>
            <td>第一个数</td>
            <td><input type="text" id="firstNum"></td>
        </tr>
        <tr>
            <td>第二个数</td>
            <td><input type="text" id="secondNum"></td>
        </tr>
        <tr>
            <td>
                <input type="button" onclick="cal('+')" value="+">
                <input type="button" onclick="cal('-')" value="-">
            </td>
            <td>

                <input type="button" onclick="cal('*')" value="*">
                <input type="button" onclick="cal('/')" value="/">
            </td>

        </tr>
        <tr>
            <td>计算结果</td>
            <td><input type="text" id="resultId"></td>
        </tr>
    </table>
    <script>

        function cal(type) {

            var num1 = document.getElementById("firstNum").value;
            var num2 = document.getElementById("secondNum").value;
            var result = eval(num1 + type + num2);
            var resultNum = document.getElementById("resultId");
            resultNum.value = result;
        }
    </script>
</body>

</html>